package com.medata.controller;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.medata.dataObject.*;
import com.medata.service.*;
import com.medata.service.impl.DocobjectServiceImpl;
import com.medata.utils.*;
import com.medata.vo.ResultVo;
import com.medata.vo.SolrReturnBean;
import com.medata.vo.SolrReturnBean_Son;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.hibernate.engine.spi.SessionImplementor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.*;
import java.util.*;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/port")
public class PortController {
    @Value("${pathname}")
    private String pathname;
    @Value("${perfix}")
    private String perfix;
    @Autowired
    private DatabaselistService databaselistService;
    @Autowired
    private GlobalsettingService globalsettingService;
    @Autowired
    private AccountService accountService;
    @Autowired
    private TemplatefieldsService templatefieldsService;
    @Autowired
    private EntityManager entityManager;
    @Autowired
    private DocobjectServiceImpl docobjectService;
    @Autowired
    private LogSearchService logSearchService;
    @Autowired
    private LogloginService logloginService;
    @Autowired
    private LogdetailService logdetailService;
    @Autowired
    private LogdispprjService logdispprjService;
    @Autowired
    private ResserverService resserverService;
    @Autowired
    private NewsInfoService newsInfoService;
    @Value("${ServerIP}")
    private String ip;

    //获取所有查询字段,所有库名
    @ResponseBody
    @ApiOperation(value = "获取所有库及字段", notes = "用于首页")
    @RequestMapping(value = "/getParams", method = RequestMethod.POST)
    public ResultVo getParams(HttpServletResponse response) {
        //接受jsonp
        getCross(response);
        List<Databaselist> databaselists = databaselistService.findAll();
        Map<String, List<Templatefields>> map = new HashMap<>();
        for (Databaselist databaselist : databaselists) {
            List<Templatefields> templatefields = templatefieldsService.getByDbid(databaselist.getDbid());
            map.put(databaselist.getDbname(), templatefields);
        }
        return ResultVOUtil.success(map);
    }

    //登入验证获取token
    @ResponseBody
    @ApiOperation(value = "登入验证获取token", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResultVo login(String username, String password, HttpServletResponse response,HttpServletRequest request) {
        getCross(response);
        Account account = accountService.findByUserName(username);
        if (account != null) {
            if (account.getPassword().equalsIgnoreCase(password)) {
                String tokenGet = TokenUtils.tokenGet(username, account.getDbids());
                //记录登入
                Loglogin loglogin=new Loglogin();
                loglogin.setActionid(200);
                loglogin.setUserip(request.getRemoteAddr());
                loglogin.setUsername(username);
                loglogin.setLogtime(Timestamp.valueOf(TimeUtil.getCurDate()));
                loglogin.setUserid(account.getUserId());
                logloginService.save(loglogin);
                Loglogin loglogin2=new Loglogin();
                loglogin2.setActionid(201);
                loglogin2.setUserip(request.getRemoteAddr());
                loglogin2.setUsername(username);
                loglogin2.setLogtime(Timestamp.valueOf(TimeUtil.getCurDate()));
                loglogin2.setUserid(account.getUserId());
                logloginService.save(loglogin2);
                return ResultVOUtil.success(tokenGet);
            }
        }
        return ResultVOUtil.erro(0, "没有该账号");
    }

    //分面+分面统计
    @RequestMapping(value = "/getFaces", method = RequestMethod.POST)
    @ApiOperation(value = "获取分面", notes = "输入需要分面的字符串,返回分面结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dbname", value = "需要分面的库", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "filterKeys", value = "过滤的字段,", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "filterValues", value = "过滤的值,", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "str", value = "分面字段,例如:责任者,题名", required = true, dataType = "String", paramType = "query"),
    })
    @ResponseBody
    public ResultVo groupGet(HttpServletRequest request,@RequestParam(value = "filterKeys",required = false) List<String> filterKeys
            , @RequestParam(value = "filterValues",required = false) List<String> filterValues, String dbname, String str, HttpServletResponse response1) {
        //接受jsonp
        getCross(response1);
        String token = request.getHeader("Authorization");
        //处理前后空格
        dbname = dbname.trim();
        token = token.trim();
        if (!token.equalsIgnoreCase("metadata666")){
            String b = TokenUtils.validToken2(token);
            if (b==null){
                return ResultVOUtil.erro(0,"登入已过期");
            }
        }
        str = str.trim();
        //转换值
        //默认字段
        if (filterKeys==null){
            filterKeys=new ArrayList<>();
            filterValues=new ArrayList<>();
        }
        String sortWord = "CreateDate:0";
        List<String> rFields = new ArrayList<>();
        rFields.add("0");
        List<String> fFields = new ArrayList<>();
        fFields.add("0");
        String str2 = str;
        Databaselist databaselist = databaselistService.findByDbtitle(dbname);
        Integer did = databaselist.getDbid();
        String dbid = String.valueOf(databaselist.getDbid());
        List<Templatefields> templatefields = templatefieldsService.getByDbid(did).stream().filter(e -> e.getTpFieldDesc().equalsIgnoreCase(str2)).collect(Collectors.toList());
        if (templatefields.size() == 0) {
            return ResultVOUtil.erro(0, "未匹配该分面字段");
        }
        List<String> list2 = new ArrayList<>();
        if (!filterKeys.isEmpty()){
            for (String s : filterKeys) {
                String fieldName = templatefieldsService.getByDbidAndTpFieldDesc(did, s).getTpFieldName();
                list2.add(s + ":" + fieldName);
            }
        }
        String strname = templatefields.get(0).getTpFieldName();
        List<String> factFields = new ArrayList<>();
        factFields.add(str + ":" + strname);
        String headXml = SolrXmlUtil.headXml(dbid);
        String returnXml = SolrXmlUtil.portReturnXml(templatefieldsService, dbid, rFields);
        String searchXml = SolrXmlUtil.portSearchXml(dbid, list2, filterValues);
        String filterXml = SolrXmlUtil.portFilterXml(fFields);
        String factXml = SolrXmlUtil.portFactXml(factFields);
        String sortXml = null;
        try {
            sortXml = SolrXmlUtil.portSortXml(sortWord);
        } catch (Exception e) {
            return ResultVOUtil.erro(0, "输入sortWords格式为: CreateDate:0");
        }
        String pageXml = SolrXmlUtil.portPsXml("1", "20");
        String xml = headXml + returnXml + "<searchfield>" + searchXml + filterXml + factXml + "</searchfield>" + sortXml + pageXml;
        JsonObject jsonObject = SolrCrudUtil.portSearch(globalsettingService, xml);
        List<Map<String, String>> list = new ArrayList<>();
        if (jsonObject != null) {
            JsonElement element = jsonObject.get("fact");
            if (element != null && element.getAsJsonArray().size() > 0) {
                JsonArray asJsonArray = element.getAsJsonArray();
                JsonObject asJsonObject = asJsonArray.get(0).getAsJsonObject();
                JsonArray factvalues = asJsonObject.get("factvalues").getAsJsonArray();
                for (JsonElement e : factvalues) {
                    Map<String, String> map = new HashMap<>();
                    JsonObject eo = e.getAsJsonObject();
                    map.put(strname, eo.get("name").getAsString());
                    map.put("total", eo.get("count").getAsString());
                    list.add(map);
                }
            }
        }
        return ResultVOUtil.success(list);
    }

    //搜索
    @RequestMapping(value = "/search", method = RequestMethod.POST)
    @ApiOperation(value = "搜索", notes = "输入需要分面的字符串,返回分面结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dbname", value = "查询数据库名 如 电子书", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "curpage", value = "查询页 ", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pagesize", value = "页面大小 ", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "sortWord", value = "排序字段后面0正1逆(默认CreateDate:0),热门排序(HitCount:1)", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "rFields", value = "List<String>返回字段(默认0全返) 例如：题名,责任者,", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "sFields", value = "List<String>查询字段(默认0查询所有)例如： 责任者:陈子游主编", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "fFields", value = "List<String>区间字段(默认0无效) 时间:2019-2020", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "faceFields", value = "list<string>分面词(默认0无效)例如：题名,责任者（时间分面：时间；时间段限定：时间2019-2020） ", required = false, dataType = "string", paramType = "query"),
    })
    @ResponseBody
    public ResultVo search(String dbname, String curpage, String pagesize, String sortWord
            , @RequestParam(value = "rFields",required = false) List<String> rFields
            , @RequestParam(value = "fFields",required = false) List<String> fFields
            , @RequestParam(value = "sFields",required = false) List<String> sFields,HttpServletRequest request
            , @RequestParam(value = "faceFields",required = false) List<String> faceFields, HttpServletResponse response) {
        getCross(response);
        String token = request.getHeader("Authorization");
        if (sortWord.isEmpty()){
            sortWord="CreateDate:0";
        }
        dbname=dbname.trim();
        Databaselist databaselist = databaselistService.findByDbtitle(dbname);
        //验证已登入权限
        String username="";
        if (!token.equalsIgnoreCase("metadata666")){
            TokenUtils.validToken(token,String.valueOf(databaselist.getDbid()));
            username= TokenUtils.validToken2(token);
        }
        if (rFields==null){
            rFields=new ArrayList<>();
            rFields.add("0");
        }else if (rFields.isEmpty()){
            rFields.add("0");
        }
        if (fFields==null){
            fFields=new ArrayList<>();
            fFields.add("0");
        }else if (fFields.isEmpty()){
            fFields.add("0");
        }
        if (faceFields==null){
            faceFields=new ArrayList<>();
            faceFields.add("0");
        }else if (faceFields.isEmpty()){
            faceFields.add("0");
        }
        if (sFields==null){
            sFields=new ArrayList<>();
            sFields.add("0");
        }else if (sFields.isEmpty()){
            sFields.add("0");
        }
        String logdoctitle="";
        Gson gson = new Gson();
        SessionImplementor session = entityManager.unwrap(SessionImplementor.class);
        Connection connection = session.connection();
        sortWord = sortWord.trim();
        Integer dbid = databaselist.getDbid();
        String dbid2 = String.valueOf(dbid);
        //拼接xml
        String headXml = SolrXmlUtil.headXml(dbid2);
        String returnXml = SolrXmlUtil.portReturnXml(templatefieldsService, dbid2, rFields);
        String sortXml = SolrXmlUtil.portSortXml(sortWord);
        String pageXml = SolrXmlUtil.portPsXml(curpage, pagesize);
        String searchXml = SolrXmlUtil.portSearchXml2(templatefieldsService, dbid2, sFields);
        String factXml = SolrXmlUtil.portFactXml2(dbid, templatefieldsService, faceFields);
        String filterXml = SolrXmlUtil.portFilterXml2(templatefieldsService, dbid, fFields);
        String xml = headXml + returnXml + "<searchfield>" + searchXml + filterXml + factXml + "</searchfield>" + sortXml + pageXml;
        //查询并封装
        System.out.println(xml);
        JsonObject jsonObject = SolrCrudUtil.portSearch(globalsettingService, xml);
        String total = jsonObject.get("total").getAsString();
        //解析返回字段并封装
        String docid = null;
        List<Map<String, Object>> map = new ArrayList<>();
        JsonArray docs = jsonObject.get("docs").getAsJsonArray();
        for (JsonElement element : docs) {
            Map<String, Object> m = new HashMap<>();
            List<Map<String, Object>> m2 = new ArrayList<>();
            List<Map<String, Object>> m3 = new ArrayList<>();
            SolrReturnBean returnBean = gson.fromJson(element, SolrReturnBean.class);
            //获取资源path
            String id = returnBean.getId();
            List<Docobject> docobjects = docobjectService.findByDocidAndDbid(id, dbid2);
            LinkedList<SolrReturnBean_Son> sons = returnBean.getField();
            m.put("id", returnBean.getId());
            docid=returnBean.getId();
            logdoctitle=returnBean.getField().get(0).getFieldvalue();
            m.put("dbid", String.valueOf(returnBean.getDBID()));
            for (SolrReturnBean_Son son : sons) {
                m.put(son.getFieldname(), son.getFieldvalue());
            }
            for (Docobject docobject : docobjects) {
                Map<String, Object> picM = new HashMap<>();
                picM.put("dbid", docobject.getDbid());
                picM.put("docid", docobject.getObjectid());
                picM.put("name", docobject.getObjectfilename());
                picM.put("path", pathname+ databaselist.getDbname() + docobject.getServerfullpath());
                if (docobject.getObjectfilename().endsWith(".jpg")){
                    m2.add(picM);
                }else {
                    m3.add(picM);
                }
            }
            m.put("pic",m2);
            m.put("pdf",m3);
            map.add(m);
        }
        JsonElement fact = jsonObject.get("fact");
        List<Map<String, Object>> flist = new ArrayList<>();
        JsonArray factvalues = fact==null?null:fact.getAsJsonArray();
        if (factvalues!=null){
            for (JsonElement e : factvalues) {
                JsonObject eo = e.getAsJsonObject();
                JsonArray factarray = eo.get("factvalues").getAsJsonArray();
                for (JsonElement element:factarray){
                    Map map1 = gson.fromJson(element, Map.class);
                    flist.add(map1);
                }
            }
        }
        ResultVo resultVo = ResultVOUtil.success(map);
        resultVo.setData2(flist);
        resultVo.setCount(total);
        //记录
        LogSearch logSearch=new LogSearch();
        Account account = accountService.findByUserName(username);
        String userid=account==null?"0":String.valueOf(account.getUserId());
        logSearch.setUserid(userid);
        logSearch.setLogTime(Timestamp.valueOf(TimeUtil.getCurDate()));
        logSearch.setUsername(username);
        logSearch.setKeyword(sFields.toString());
        logSearch.setActionId(300);
        logSearch.setResultcount(Integer.valueOf(total));
        logSearch.setUserip(request.getRemoteAddr());
        logSearchService.save(logSearch);
        if (total.equalsIgnoreCase("1")){
            //记录浏览详情
            Logdetail logdetail=new Logdetail();
            logdetail.setLogtime(Timestamp.valueOf(TimeUtil.getCurDate()));
            logdetail.setUsername(username);
            logdetail.setActionid(String.valueOf(400));
            logdetail.setUserip(request.getRemoteAddr());
            logdetail.setDocid(docid);
            logdetail.setDoctitle(logdoctitle);
            logdetail.setUserid(userid);
            logdetailService.save(logdetail);
            //hotcount+1
            try {
                String sql="select HitCount from "+dbname+" where docid =?";
                PreparedStatement ps = connection.prepareStatement(sql);
                ps.setString(1,docid);
                ResultSet rs = ps.executeQuery();
                String hitcount=null;
                while (rs.next()){
                    hitcount=rs.getString(1);
                }
                if (hitcount.isEmpty()){
                    hitcount="0";
                }
                hitcount=String.valueOf(Integer.valueOf(hitcount+1));
                String sql2="update "+dbname+" set HitCount = ? where docid = ?";
                PreparedStatement ps2 = connection.prepareStatement(sql2);
                ps2.setString(1,hitcount);
                ps2.setString(2,docid);
                ps2.execute();
            }catch (Exception e){
                e.printStackTrace();
            }

        }
        return resultVo;
    }

    //下载和打开文件
    @ApiOperation(value = "下载/打开文件", notes = "(text,xml,jpg,png,mp4,pdf可以直接打开)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "objid", value = "资源的id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "handle", value = "填down或open", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/filesHandle", method = RequestMethod.GET)
    public String fileHandle(Model model,String objid, String handle, HttpServletResponse response,HttpServletRequest request) {
        //接受jsonp
        getCross(response);
        Resserver resserver = resserverService.findByServerport("6896");
        String filePath=resserver.getRespath();
        String token = request.getHeader("Authorization");
        //处理前后空格
//        token = token.trim();
        objid = objid.trim();
        handle = handle.trim();
        String username="";
        //验证权限
        if (!token.equalsIgnoreCase("metadata666")){
            username= TokenUtils.validToken2(token);
        }
        if (handle.equalsIgnoreCase("down")) {
            FileUploadUtil.fileDown(docobjectService, objid, databaselistService, filePath, response);
            return null;
        } else if (handle.equalsIgnoreCase("open")) {
            Docobject docobject = docobjectService.findAllByObjectid(objid);
            String serverfullpath = docobject.getServerfullpath();
            String filename = docobject.getObjectfilename();
            String uid = UidUtil.getUid();
            Databaselist databaselist = databaselistService.findByDbid(Integer.valueOf(docobject.getDbid()));
            String dbaname=databaselist.getDbname();
            String tempPath = filePath + "/tempFiles/" + dbaname + "/" + uid;
            File tempFile = new File(tempPath);
            if (!tempFile.exists()) {
                tempFile.mkdirs();
            }
            File file1 = new File(filePath + "/" + dbaname + "/" + docobject.getServerfullpath());
            filename = filename.replaceAll("%", "");
            String newName = tempPath + "/" + filename;
            File file2 = new File(newName);
            //记录
            Logdispprj logdispprj=new Logdispprj();
            logdispprj.setActionid("500");
            logdispprj.setFilesize((int)(file2.length()/1024));
            logdispprj.setLogtime(Timestamp.valueOf(TimeUtil.getCurDate()));
            logdispprj.setPrjectname(filename);
            logdispprj.setUsername(username);
            logdispprj.setUserid("0");
            logdispprj.setUserip(request.getRemoteAddr());
            logdispprjService.save(logdispprj);
            try {
                FileUtils.copyFile(file1, file2);
                if (filename.endsWith(".pdf")) {
                    String url = ip +perfix+ "/pdfjs/web/viewer.html?file=" + ip +perfix+ "/tempFiles/" + dbaname + "/" + uid + "/" + filename;
                    long length = file2.length();
                    long c = 10485760;
                    long time = length / c;
                    time = time * 1000 + 1000;
                    model.addAttribute("pdfname", docobject.getObjectfilename());
                    model.addAttribute("pdfurl", url);
                    model.addAttribute("waitTime", time);
                    return "pdfview";
                } else if (filename.endsWith(".xml") || filename.endsWith(".text")) {
                    List<String> list = FileUtils.readLines(file2, "utf-8");
                    return list.toString();
                } else {
                    InputStream is = null;
                    OutputStream os = null;
                    try {
                        response.setContentType("image/jpeg");
                        response.addHeader("Content-Length", "" + file2.length());
                        is = new FileInputStream(file2);
                        os = response.getOutputStream();
                        IOUtils.copy(is, os);
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        if (os != null) {
                            os.flush();
                            os.close();
                        }
                        if (is != null) {
                            is.close();
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            return "error/400";
        }
        return null;
    }

    //sortlist查询
    @ApiOperation(value = "SortList查询", notes = "(text,xml,jpg,png,mp4,pdf可以直接打开)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentID", value = "父级ID,默认0", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "sortValue", value = "分类英文编号", required = false, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/sortListGet",method = RequestMethod.POST)
    @ResponseBody
    public ResultVo sortListGet(String parentID,String sortValue,HttpServletResponse response){
        getCross(response);
        SessionImplementor session = entityManager.unwrap(SessionImplementor.class);
        if (parentID==null){
            parentID="0";
        }
        List<Map<String,String>> list=new ArrayList<>();
        try {
            Connection connection = session.connection();
            boolean flag=(sortValue==null||sortValue.isEmpty())?false:true;
            String sql=null;
            if (flag){
                sql="select * from sortlist where SortParentID = (\n" +
                        "\tselect SortParentID from SortList where SortValue = ?\n" +
                        ")";
            }else{
                sql="select SortName,SortValue,SortID from SortList where SortParentID =?";
            }
            PreparedStatement ps = connection.prepareStatement(sql);
            if (flag){
                ps.setString(1,sortValue);
            }else{
                ps.setString(1,parentID);
            }
            ResultSet rs = ps.executeQuery();
            while (rs.next()){
                Map<String,String> map=new HashMap<>();
                map.put("sortName",rs.getString(1));
                map.put("sortValue",rs.getString(2));
                map.put("SortID",rs.getString(3));
                list.add(map);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultVOUtil.success(list);
    }


    @RequestMapping(value = "/oneNewGet",method = RequestMethod.POST)
    @ApiOperation(value = "根据newsId获取单挑新闻")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "newsId", value = "新闻ID", required = true, dataType = "integer", paramType = "query"),
    })
    @ResponseBody
    public ResultVo oneNewGet(Integer newsId,HttpServletResponse response){
        getCross(response);
        NewsInfo info = newsInfoService.findByNewId(newsId);
        Map<String,String> map=new HashMap<>();
        map.put("title",info.getTitle());
        map.put("content",info.getContent());
        map.put("languagetype",info.getLanguagetype());
        map.put("newId",info.getNewId().toString());
        return ResultVOUtil.success(map);
    }

    @RequestMapping(value = "/newsGet",method = RequestMethod.POST)
    @ApiOperation(value = "输入页码获取新闻")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码:数字类型", required = true, dataType = "integer", paramType = "query"),
    })
    @ResponseBody
    public ResultVo newsGet(Integer page,HttpServletResponse response){
        getCross(response);
        List<NewsInfo> news = newsInfoService.find(page, 15);
        List<Map<String,String>> list=new ArrayList<>();
        for (NewsInfo info:news){
            Map<String,String> map=new HashMap<>();
            map.put("title",info.getTitle());
            map.put("time",info.getTime().toString());
            map.put("languagetype",info.getLanguagetype());
            map.put("newId",info.getNewId().toString());
            list.add(map);
        }
        ResultVo resultVo = ResultVOUtil.success(list);
        SessionImplementor session = entityManager.unwrap(SessionImplementor.class);
        Connection connection = session.connection();
        try {
            String sql="select count(*) from NewsInfo";
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()){
                resultVo.setCount(rs.getString(1));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return resultVo;
    }



    //跨域方法
    public static void getCross(HttpServletResponse response) {
        //接受jsonp
        response.setContentType("text/plain");
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setHeader("Access-Control-Allow-Origin", "*");//添加跨域访问
    }

}
